package dp.metel.likeme.common.jaxrs.interceptor;

import javax.servlet.http.HttpServletRequest;

import org.apache.catalina.tribes.group.interceptors.GzipInterceptor;
import org.apache.cxf.phase.AbstractPhaseInterceptor;
import org.apache.cxf.phase.Phase;
import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.message.Message;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class RequestReceiverInterceptor extends AbstractPhaseInterceptor<Message> {
	
	private static final Logger logger = LoggerFactory.getLogger(RequestReceiverInterceptor.class);
	
	public RequestReceiverInterceptor(){
		super(Phase.RECEIVE);
		addBefore(GzipInterceptor.class.getName()); 		
	}

	@Override
	public void handleMessage(Message message) throws Fault {

		try{
			HttpServletRequest request = (HttpServletRequest) message.get("HTTP.REQUEST");
			String uri = request.getRequestURI();
			if(uri.indexOf("/ping") >= 0){
				logger.debug("work task >>> ping "); 
			}
			if(uri.indexOf("/version") >= 0){
				logger.debug("work task >>> version invoking ...... "); 
			}

		} catch(Exception e	){
			e.printStackTrace(); 
			logger.error("invoke exception << work task [ping]");
		}				
				
	}
	
	

}
